package com.common.filter;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.service.imp.ReceiptService;

public class IsMonthPDInterceptor extends AbstractInterceptor{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9162592873994158339L;
	private String tip;
	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		HttpSession session = ServletActionContext.getRequest().getSession();
		ServletContext sc =session.getServletContext();
		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		ReceiptService receiptService=(ReceiptService)ctx.getBean("receiptService");
		if(receiptService.isMonthPD()){
			return arg0.invoke();
		}else{
			ActionContext actx = ActionContext.getContext();  
			actx.put("tip", "本月已经盘点，操作被终止");
			return "true";

		}
	}
	public String getTip() {
		return tip;
	}
	public void setTip(String tip) {
		this.tip = tip;
	}

}
